Skip to content

[docs] Add basic rules for routes#1245

Open
andrewnicols wants to merge 1 commit intomoodle:mainfrom
andrewnicols:pageRoutingRules
Open

[docs] Add basic rules for routes#1245
andrewnicols wants to merge 1 commit intomoodle:mainfrom
andrewnicols:pageRoutingRules

Conversation

@andrewnicols
Copy link
Member

@andrewnicols andrewnicols commented Jan 29, 2025

This is an initial set of rules for routes.

I've tried to keep things relatively simple but I may have dumbed it down too much.

@netlify
Copy link

netlify bot commented Jan 29, 2025

Deploy Preview for moodledevdocs ready!

Name Link
🔨 Latest commit 22aeb3f
🔍 Latest deploy log https://app.netlify.com/sites/moodledevdocs/deploys/679a18a442cb330008282159
😎 Deploy Preview https://deploy-preview-1245--moodledevdocs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 29, 2025

⚡️ Lighthouse report for the deploy preview of this PR

URL Performance Accessibility Best Practices SEO PWA Report
/ 🔴 33 🟢 95 🟢 100 🟢 90 🟢 100 Report
/docs/5.0/apis/commonfiles 🟠 53 🟢 93 🟢 100 🟢 100 🟢 100 Report
/general/development/gettingstarted 🟠 55 🟢 95 🟢 100 🟢 90 🟢 100 Report
/general/releases 🟠 65 🟢 95 🟢 100 🟢 100 🟢 100 Report

@kabalin
Copy link
Collaborator

kabalin commented Jan 29, 2025


:::tip Singular or Plural

Where present, entities should always be in the plural form.
Copy link
Collaborator

@kabalin kabalin Jan 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree regarding plural form. Should examples for course entity be changed accordingly?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to strictly follow the subsystems names here.
However, in the example of course, /courses/<courseid>/view sounds not correct, as you are only going to ever look at a singular course. So I think in this case singular is the way to go.
Not sure how we make the docs clearer though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment the component resolution is automatic based on the location of the class and we automatically normalise it.

If we want to do something different then we'll have to work out the best way of doing so and in which situations.

Copy link
Collaborator

@kabalin kabalin Jan 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, in the example of course, /courses/<courseid>/view sounds not correct, as you are only going to ever look at a singular course. So I think in this case singular is the way to go.

Yeah, it is sounds not correct in individual scenario, unless one see it as query "select <courseid> from courses". Thinking in broader context, what will be the endpoint for querying list of courses? Different /courses path or /course/list action? Something better to consider while we are at early stage I guess :)

With regard to this "tip", to avoid contradition for now we might say "Where possible, entities should be in the plural form."

PS In Martin Fowler's REST maturity model article all entities are plural (Level 1 onwards).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Andrew's point is a good one that resolution is based on automatic resolution. Messing around with that feels like it may add more complexity than it's worth.
Also, thanks for the extract context Ruslan

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In REST APIs, entities are usually in plural. E.g. using /courses/<courseid> is the standard way to obtain a course. As mentioned previously, you should read it as "get from the selection of courses".

But as it was also mentioned, this adds complexity because there is no easy way to pluralise an entity name that isn't in plural. E.g. what is the plural of mod_data? How can we detect if an entity is already in plural form or not?

We could let entities specify a "plural form" to be used, but this can lead to conflicts between different components. E.g. imagine that mod_data and mod_database (in case it existed) both define "databases" as the plural form, we would have a conflict there.

So I guess the best solution is to just calculate the name automatically and use it as it is. So it would be /course, /grade, /user and so on.

The question then is: do we want to recommend people to use plural forms in their folders/components from now on? Because I guess we won't migrate existing components to plural (e.g. move code from /course to /courses), so if we recommend using plural form we'll end up with a mix of singular and plural names. Actually, we'll already have a mix because some folders like /blocks or /notes are already in plural 😅

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's exactly why I think singular makes more sense: course/list is a list of course objects. course/1 is to get/update/delete course 1. Now that does mean that you would have to resolve the endpoints in a specific order so that 'list' is not treated as a course identifier such as idnumber. The simplest way to avoid this artificial limitation while avoiding namespace conflicts needs to use namespaces. Namespaces might seem ugly, but it's for programmers and computers, and both might be convinced of the simplicity gains. So instead: core_course/courses/list and core_course/course/1. mod_data/databases/* and mod_database/databases/* endpoints are therefore separate. The full frankenstyle name seems like a good preexisting namespace option to leverage.

@andrewnicols
Copy link
Member Author

andrewnicols commented Jan 29, 2025 via email

In many cases an entity may have related child entities, or _sub-entities_. These should be placed after the primary or default entity's identifier, for example:

```
/rest/api/v2/course/<courseid>/section/<sectionid>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, the term "section" refers to the entity, correct? Then, based on the earlier advice about plural entities, shouldn't it be "sections" in the plural form?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants